package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/reveal-cards-in-increasing-order/">950. 按递增顺序显示卡牌</a>
 */
public class Solution950 extends BaseSolution {

    public int[] deckRevealedIncreasing(int[] deck) {
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < deck.length; i++) {
            queue.offer(i);
        }
        Arrays.sort(deck);
        int[] rst = new int[deck.length];
        for (int v : deck) {
            rst[queue.poll()] = v;
            if (queue.isEmpty()) {
                break;
            }
            queue.offer(queue.poll());
        }
        return rst;
    }

    public static void main(String[] args) {
        Solution950 solution = new Solution950();
    }
}